package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class JDBCDemo10 {
    public static void main(String[] args) {
        try (Connection connection = DButil.getConnection()) {
            connection.setAutoCommit(false);
            String sql = "DELETE FROM user WHERE id = ?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setInt(1,5);
            int num = ps.executeUpdate();
            System.out.println(num > 0 ? "修改成功！" : "修改失败！");
//            connection.rollback();
//            System.out.println("事务回滚，操作未完成！！！");
            connection.commit();
            System.out.println("事务提交成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
